﻿using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.ObjectModel;
using Wpf.Ui;
using Wpf.Ui.Controls;

namespace MetaView.Main.ViewModels
{
    public partial class MainWindowViewModel : ViewModel
    {
        private bool _isInitialized = false;

        [ObservableProperty]
        private string _applicationTitle = string.Empty;

        [ObservableProperty]
        private string _moduleTitle = string.Empty;

        [ObservableProperty]
        private ObservableCollection<object> _navigationItems;

        [ObservableProperty]
        private ObservableCollection<object> _navigationFooter;

        [ObservableProperty]
        private ObservableCollection<MenuItem> _trayMenuItems;

        /// <summary>
        /// 是否初始化完成
        /// </summary>
        public bool IsInitialized
        {
            get { return _isInitialized; }
            set { _isInitialized = value; }
        }

        /// <summary>
        /// 应用程序标题
        /// </summary>
        public string ApplicationTitle
        {
            get { return _applicationTitle; }
            set { _applicationTitle = value; }
        }

        /// <summary>
        /// 导航栏项目
        /// </summary>
        public ObservableCollection<object> NavigationItems
        {
            get { return _navigationItems; }
            set { _navigationItems = value; }
        }

        /// <summary>
        /// 导航栏脚注
        /// </summary>
        public ObservableCollection<object> NavigationFooter
        {
            get { return _navigationFooter; }
            set { _navigationFooter = value; }
        }

        /// <summary>
        /// 托盘菜单项
        /// </summary>
        public ObservableCollection<MenuItem> TrayMenuItems
        {
            get { return _trayMenuItems; }
            set { _trayMenuItems = value; }
        }        

        //[System.Diagnostics.CodeAnalysis.SuppressMessage("Style","IDE0060:Remove unused parameter",Justification = "Demo")]
        public MainWindowViewModel(INavigationService navigationService)
        {
            if (!IsInitialized)
            {
                InitializeViewModel();
            }
        }

        /// <summary>
        /// 初始化视图模型
        /// </summary>
        private void InitializeViewModel()
        {
            ApplicationTitle = "WPF UI - MVVM Demo";

            _navigationItems = new ObservableCollection<object>
            {
                new NavigationViewItem()
                {
                    Content = "Home",
                    Icon = new SymbolIcon { Symbol = SymbolRegular.Home24 },
                    TargetPageType = typeof(Views.Pages.DashboardPage),
                },
                new NavigationViewItem()
                {
                    Content = "Data",
                    Icon = new SymbolIcon { Symbol = SymbolRegular.DataHistogram24 },
                    TargetPageType = typeof(Views.Pages.DataPage),
                }
            };

            _navigationFooter = new ObservableCollection<object>
            {
                new NavigationViewItem()
                {
                    Content = "Settings",
                    Icon = new SymbolIcon { Symbol = SymbolRegular.Settings24 },
                    TargetPageType = typeof(Views.Pages.SettingsPage),
                }
            };

            _trayMenuItems = new ObservableCollection<MenuItem>
            {
                new MenuItem() { Header = "Home", Tag = "tray_home" }
            };

            _isInitialized = true;
        }
    }
}
